package com.framework.common.message;

import com.framework.common.utils.QuickHelper;

public class MessagePacket {

    private String type;
    private String targetId;
    private MessagePacketData data;
    private Integer adddate = 0;
    public String getType() {
        return type;
    }

    public String getTargetId() {
        return targetId;
    }

    public void setTargetId(String targetId) {
        this.targetId = targetId;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setType(PacketType type) {
        this.type = type.toString();
    }

    public Integer getAdddate() {
        return adddate;
    }

    public void setAdddate(Integer adddate) {
        this.adddate = adddate;
    }

    public MessagePacketData getData() {
        return data;
    }

    public MessagePacket(){
        this.adddate = QuickHelper.getNowTimeStampSeconds();
    }

    public void setData(MessagePacketData data) {
        this.data = data;
    }

    public static MessagePacket createPacket(String type, String targetId, MessagePacketData data) {
        User user = new User();
        return createPacket(type, targetId, data, user);
    }

    public static MessagePacket createPacket(String type,String targetId,MessagePacketData data,User user) {
        MessagePacket packet = new MessagePacket();
        packet.setType(type);
        packet.setData(data);
        packet.setTargetId(targetId);
        return packet;
    }

    public static MessagePacketData createPacketData(MessageType type,Object data) {
        return createPacketData(type,data,new User());
    }

    public static MessagePacketData createPacketData(MessageType type,Object data,User user) {
        return createPacketData(type, 1, data, user);
    }

    public static MessagePacketData createPacketData(MessageType type,Integer code,Object data,User user) {
        MessagePacketData packetData = new MessagePacketData();
        packetData.setCode(code);
        packetData.setContent(data);
        packetData.setType(type);
        //packetData.setType(MessageType.valueOfName(type));
        packetData.setUser(user);
        return packetData;
    }
}
